listen

open suspend override fun listen(channel: String, f: (Notification) -> Unit)

Listens for notifications from a specified PostgreSQL channel.

The method establishes a subscription to a PostgreSQL channel using the LISTEN/NOTIFY mechanism. When a notification is received on the subscribed channel, the provided callback function is invoked with the notification object as a parameter. This method delegates the functionality to a variant that supports multiple channels.

Parameters

channel

The name of the PostgreSQL channel to listen to. Must not be blank.

f

A callback function to handle notifications. The function receives a Notification object containing the channel name and payload.

Throws

If the channel parameter is blank.


open suspend override fun listen(channels: List<String>, f: (Notification) -> Unit)

Listens for notifications from the specified PostgreSQL channels.

The method establishes a subscription to one or more PostgreSQL channels using the LISTEN/NOTIFY functionality. When a notification is received on one of the subscribed channels, the provided callback function is invoked with the notification object as a parameter. The method ensures that channel names are valid and automatically attempts to reconnect if the connection is closed.

Parameters

channels

A list of PostgreSQL channel names to listen to. Must not be empty.

f

A callback function to handle notifications. The function receives a Notification object containing the channel name and payload.

Throws

If the channels list is empty or any channel name is blank.